package com.hotline.monitor.service.quality;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hotline.monitor.enums.ReturnCodeEnum;
import com.hotline.monitor.util.HttpUtils;
import com.hotline.monitor.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.Map;

/**
 * <p>
 * 类
 * </p>
 *
 * @author yeshengqi
 * @since 2023-08-19 15:06
 */
@Service
@Slf4j
public class QualityControlServiceImpl implements QualityControlService{

    private static final String URI_QUALITY_CONTROL_FORCE_LOGOUT = "/agentgateway/resource/qualitycontrol/{}/forcelogout/{}";

    @Value("${hotline.url}")
    private String url;

    @Override
    public void forceLogout(String agentId, String workNo, Map header) {
        try{
            String reqUrl = url + URI_QUALITY_CONTROL_FORCE_LOGOUT;
            reqUrl = StringUtils.arrayFormat(reqUrl,new String[]{agentId,workNo});

            String resultString = HttpUtils.doDeleteJson(reqUrl,header);
            log.info("强制签出结果返回：{}",resultString);
            if(StringUtils.isNotBlank(resultString)){
                JSONObject jsonObject = JSON.parseObject(resultString);
                if(ReturnCodeEnum.SUCCESS.getCode().equals(jsonObject.getString("retcode"))){
                    log.info("强制签出失败");
                }
            }
        }catch (Exception e){
            log.error("强制签出失败:{}",e);
        }
    }
}
